/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */
package org.ipig.commons.codec;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

/**
 * 编码解码服务
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $Id: CodecService.java 3 2020-01-21 09:36:33Z ts <comchnts@163.com> $
 * @since 1.0
 */
public interface CodecService {
    /**
     * 编码
     *
     * @param object       object
     * @param outputStream OutputStream
     * @throws IOException IOException
     */
    void encode(final Object object, OutputStream outputStream) throws IOException;

    /**
     * 编码
     *
     * @param object Object
     * @return byte[]
     * @throws IOException IOException
     */
    byte[] encode(final Object object) throws IOException;

    /**
     * 解码一个给定类型的对象
     *
     * @param inputStream InputStream
     * @param type        Class<T>
     * @return <T>
     * @throws IOException IOException
     */
    <T> T decode(InputStream inputStream, final Class<T> type) throws IOException;

    /**
     * 解码一个给定类型的对象
     *
     * @param bytes byte[]
     * @param type  Class<T>
     * @return <T>
     * @throws IOException IOException
     */
    <T> T decode(byte[] bytes, final Class<T> type) throws IOException;

}

